package com.bestillet.kyllingogco;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class ShopArrayAdapter extends ArrayAdapter<Shop> {
	private ArrayList<Shop> shops;
	
	private Activity context;
	
	public ShopArrayAdapter(Context context, ArrayList<Shop> shops) {
		super(context, R.layout.shop_item, shops);
		this.context = (Activity) context;
		this.shops = shops;
	}

	static class ViewHolder {
		protected TextView text;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Shop shop = shops.get(position);
		View view = null;
		if (convertView == null) {
			LayoutInflater inflator = context.getLayoutInflater();
			view = inflator.inflate(R.layout.shop_item, parent, false);
			final ViewHolder viewHolder = new ViewHolder();
				
			viewHolder.text = (TextView) view.findViewById(R.id.lblShopName);
			view.setTag(viewHolder);
		} else {
			view = convertView;
		}
		
		ViewHolder holder = (ViewHolder) view.getTag();
		holder.text.setText(shop.getName());
		return view;
	}
}